<?xml version="1.0" encoding="UTF-8"?>
<!-- 
	Copyright (c) 2012 Mia-Software. All rights reserved. This program and 
	the accompanying materials are made available under the terms of the Eclipse 
	Public License v1.0 which accompanies this distribution, and is available 
	at http://www.eclipse.org/legal/epl-v10.html 
	
	Contributors: 
		Herve ESTEGUET (Mia-Software) - Bug 381352 - [Releng] There must be a project to configure the build by tycho
-->
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common"
	extension-element-prefixes="exsl" xmlns:m2="http://maven.apache.org/POM/4.0.0">
	<xsl:output indent="yes" />
	<xsl:param name="updatesites" />
	<xsl:param name="testDependencies" />
	<xsl:param name="tychoVersion" />
	<xsl:param name="tychoExtrasVersion" />
	<xsl:param name="relengDir" />
	<xsl:param name="antVersionNumber" />
	<xsl:param name="workspaceLoc" />
	<xsl:param name="buildDirectoryName" />
	
	<xsl:template match="/">
		<project
			xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
			xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<xsl:apply-templates select="//m2:project/*" />
			<properties>
				<!-- Tycho settings -->
				<tycho-version>
					<xsl:value-of select="$tychoVersion" />
				</tycho-version>
				<tycho-extras-version>
					<xsl:value-of select="$tychoExtrasVersion" />
				</tycho-extras-version>
				<!-- update sites settings -->
				<download.eclipse.org.mirror>download.eclipse.org
				</download.eclipse.org.mirror>
				<!-- Others settings -->
				<maven.compile.deprecation>false</maven.compile.deprecation>
				<maven.test.failure.ignore>true</maven.test.failure.ignore>
				<ant.version.number>
					<xsl:value-of select="$antVersionNumber" />
				</ant.version.number>
			</properties>
			<!-- Remove this when stop using tycho snapshot versions -->
			<pluginRepositories>
				<pluginRepository>
					<!-- temporary workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=360628 -->
					<id>tycho-snapshots</id>
					<url>https://oss.sonatype.org/content/groups/public/</url>
					<releases>
						<enabled>false</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
			<xsl:copy-of select="document($updatesites)/*" />
		</project>
	</xsl:template>
	<xsl:template match="m2:build">
		<build>
			<directory><xsl:value-of select="$buildDirectoryName" /></directory>
			<plugins>
				<xsl:copy-of select="m2:plugins/*" />
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-antrun-plugin</artifactId>
					<version>1.7</version>
					<executions>
						<execution>
							<id>acknowledge-build-qualifier</id>
							<phase>package</phase>
							<goals>
								<goal>run</goal>
							</goals>
							<configuration>
								<target>
									<property name="buildQualifier">${project.buildQualifier}</property>
									<property name="releng.dir"><xsl:value-of select="$relengDir" /></property>
									<xsl:element name="ant">
										<xsl:attribute name="antfile">
											<xsl:value-of select="concat($relengDir, '/ant-scripts.xml')" />
										</xsl:attribute>
										<xsl:attribute name="target">store-build-qualifier</xsl:attribute>
										<xsl:attribute name="inheritRefs">true</xsl:attribute>
									</xsl:element>
								</target>
							</configuration>
						</execution>
						<execution>
							<id>generate-doc</id>
							<phase>generate-resources</phase>
							<goals>
								<goal>run</goal>
							</goals>
							<configuration>
								<target>
									<property name="WORKSPACE"><xsl:value-of select="$workspaceLoc" /></property>
									<property name="releng.dir"><xsl:value-of select="$relengDir" /></property>
									<xsl:element name="ant">
										<xsl:attribute name="antfile">
											<xsl:value-of select="concat($relengDir, '/ant-scripts.xml')" />
										</xsl:attribute>
										<xsl:attribute name="target">generate-documentation</xsl:attribute>
										<xsl:attribute name="inheritRefs">true</xsl:attribute>
									</xsl:element>
								</target>
							</configuration>
						</execution>
					</executions>
					<dependencies>
						<dependency>
							<groupId>net.sf.saxon</groupId>
							<artifactId>saxon</artifactId>
							<version>8.7</version>
						</dependency>
						<dependency>
							<groupId>ant-contrib</groupId>
							<artifactId>ant-contrib</artifactId>
							<version>1.0b3</version>
							<exclusions>
								<exclusion>
									<groupId>ant</groupId>
									<artifactId>ant</artifactId>
								</exclusion>
								<exclusion>
									<groupId>org.apache.ant</groupId>
									<artifactId>ant</artifactId>
								</exclusion>
							</exclusions>
						</dependency>
					</dependencies>
				</plugin>
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<artifactId>tycho-source-plugin</artifactId>
					<version>${tycho-version}</version>
					<executions>
						<execution>
							<id>plugin-source</id>
							<goals>
								<goal>plugin-source</goal>
							</goals>
						</execution>
					</executions>
				</plugin>
				<!-- We could use the plugin below instead of manually generate sources 
					features using ant. To do so, some refactoring of the current features are 
					needed -->
				<!-- plugin> <groupId>org.eclipse.tycho.extras</groupId> <artifactId>tycho-source-feature-plugin</artifactId> 
					<version>${tycho-extras-version}</version> <executions> <execution> <id>source-feature</id> 
					<phase>package</phase> <goals> <goal>source-feature</goal> </goals> </execution> 
					</executions> </plugin -->
				<!-- You could uncomment the lines below if you are using tycho >= 0.15 -->
				<!-- plugin>
					<groupId>org.eclipse.tycho</groupId>
					<artifactId>tycho-p2-plugin</artifactId>
					<version>${tycho-version}</version>
					<executions>
						<execution>
							<id>attached-p2-metadata</id>
							<phase>package</phase>
							<goals>
								<goal>p2-metadata</goal>
							</goals>
							<configuration>
								<defaultP2Metadata>false</defaultP2Metadata>
							</configuration>
						</execution>
					</executions>
				</plugin>
				<plugin>
					<groupId>org.eclipse.tycho.extras</groupId>
					<artifactId>tycho-pack200a-plugin</artifactId>
					<version>${tycho-extras-version}</version>
					<executions>
						<execution>
							<id>pack200-normalize</id>
							<goals>
								<goal>normalize</goal>
							</goals>
						</execution>
					</executions>
				</plugin>
				<plugin>
					<groupId>org.eclipse.tycho.extras</groupId>
					<artifactId>tycho-pack200b-plugin</artifactId>
					<version>${tycho-extras-version}</version>
					<executions>
						<execution>
							<id>pack200-pack</id>
							<goals>
								<goal>pack</goal>
							</goals>
						</execution>
					</executions>
				</plugin -->
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<version>${tycho-version}</version>
					<artifactId>tycho-packaging-plugin</artifactId>
					<configuration>
						<strictBinIncludes>false</strictBinIncludes>
						<archiveSite>true</archiveSite>
					</configuration>
					<executions>
						<execution>
							<goals>
								<goal>build-qualifier</goal>
							</goals>
							<configuration>
								<xsl:comment>
									We want the qualifier of bundles to be suffixed by 'v'
								</xsl:comment>
								<format>'v'yyyyMMddHHmm</format>
							</configuration>
						</execution>
					</executions>
				</plugin>
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<version>${tycho-version}</version>
					<artifactId>target-platform-configuration</artifactId>
					<configuration>
						<allowConflictingDependencies>true</allowConflictingDependencies>
						<includePackedArtifacts>true</includePackedArtifacts>
					</configuration>
				</plugin>
			</plugins>
		</build>
	</xsl:template>
	<xsl:template match="m2:modules">
		<modules>
			<xsl:copy-of select="*" />
		</modules>
	</xsl:template>
	<xsl:template match="*[name()!='build'][name()!='modules']">
		<xsl:copy-of select="." />
	</xsl:template>
</xsl:stylesheet>
